package heima_case;

import java.util.Random;

public class VerificationCode {
    public static void main(String[] args) {
        int n = 9;
        String code = createCode(n);
        System.out.println(n + "位数验证码为" + code);
    }

    public static String createCode(int n){
        Random r = new Random();
        String code = "";
        for(int i = 1; i <= n; i++){
            int type = r.nextInt(3);
            switch (type){
                case 0: //随机一个数字
                    code += r.nextInt(10);
                    break;
                case 1: //随机一个大写字符 A：65 Z：65+25
                    char ch1 = (char)(r.nextInt(26) + 65);
                    code += ch1;
                    break;
                case 2: //随机一个小写字符 a：97 z：97+25
                    char ch2 = (char)(r.nextInt(26) + 97);
                    code += ch2;
                    break;
            }
        }
        return code;
    }
}
